/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            inspectionRouteInfo: {
                inspectionRoutes: [],
                route:{},
                _currentTab:'inspectionRoutePoint',
                total: 0,
                records: 1,
                moreCondition: false,
                inspectionPoint: false,
                routeName: '',
                conditions: {
                    routeName: '',
                    inspectionRouteId: '',
                    seq: ''
                }
            }
        },
        _initMethod: function () {
            $that._listInspectionRoutes(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('inspectionRoute', 'listInspectionRoute', function (_param) {
                $that._listInspectionRoutes(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('inspectionRoute', 'goBack', function (_param) {
                $that.inspectionRouteInfo.inspectionPoint = false;
            });
            vc.on('inspectionRoute', 'paginationPlus', 'page_event', function (_currentPage) {
                $that._listInspectionRoutes(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listInspectionRoutes: function (_page, _rows) {
                $that.inspectionRouteInfo.conditions.page = 1;
                $that.inspectionRouteInfo.conditions.row = 1000;
                $that.inspectionRouteInfo.conditions.communityId = vc.getCurrentCommunity().communityId;
                let param = {
                    params: $that.inspectionRouteInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/inspectionRoute.listInspectionRoutes',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.inspectionRouteInfo.total = _json.total;
                        $that.inspectionRouteInfo.records = _json.records;
                        $that.inspectionRouteInfo.inspectionRoutes = _json.inspectionRoutes;
                        // vc.emit('inspectionRoute', 'paginationPlus', 'init', {
                        //     total: $that.inspectionRouteInfo.records,
                        //     dataCount: $that.inspectionRouteInfo.total,
                        //     currentPage: _page
                        // });
                        if (_json.inspectionRoutes && _json.inspectionRoutes.length > 0) {
                            $that._switchInspectionRoute(_json.inspectionRoutes[0]);
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddInspectionRouteModal: function () {
                vc.emit('addInspectionRoute', 'openAddInspectionRouteModal', {});
            },
            _openEditInspectionRouteModel: function (_inspectionRoute) {
                vc.emit('editInspectionRoute', 'openEditInspectionRouteModal', _inspectionRoute);
            },
            _openDeleteInspectionRouteModel: function (_inspectionRoute) {
                vc.emit('deleteInspectionRoute', 'openDeleteInspectionRouteModal', _inspectionRoute);
            },
            //查询
            _queryInspectionRouteMethod: function () {
                $that._listInspectionRoutes(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetInspectionRouteMethod: function () {
                $that.inspectionRouteInfo.conditions.inspectionRouteId = '';
                $that.inspectionRouteInfo.conditions.routeName = '';
                $that.inspectionRouteInfo.conditions.seq = '';
                $that._listInspectionRoutes(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openInspectionPointModel: function (_inspectionRoute) {
                $that.inspectionRouteInfo.inspectionPoint = true;
                vc.emit('inspectionRoutePoint', 'listInspectionPoint', _inspectionRoute);
            },

            //重置
            _switchInspectionRoute: function (_route) {
                $that.inspectionRouteInfo.route = _route;
                $that.changeTab($that.inspectionRouteInfo._currentTab);
            },
            changeTab: function (_tab) {
                $that.inspectionRouteInfo._currentTab = _tab;
                vc.emit(_tab, 'switch', $that.inspectionRouteInfo.route);
            },
            _moreCondition: function () {
                if ($that.inspectionRouteInfo.moreCondition) {
                    $that.inspectionRouteInfo.moreCondition = false;
                } else {
                    $that.inspectionRouteInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);